﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static student s1 = new student("10098","张扬","20");

        static student s2 = new student("10688", "洋洋", "20");

        static student s3 = new student("10328", "李华", "219");

        static student s4 = new student("10068", "余华", "21");
        static student s5 = new student("10028", "明华", "22");


        //        添加3个类，分别实现 IComparer<T>接口，实现对Student类的三个字段的排序。
        //1、学生类：学号、姓名、年龄
        //2、请选择：1、添加学生信息。2、删除学生信息 2、查询学生信息。
        //3、重复的学号不能添加。
        //4、查询学生信息功能中有：1、查询所有（按学号排序）2、查询所有（按姓名排序），2、查询所有（按年龄排序）4、按学号查询（查没有，则打印查无此学生）5、退出

        static List<student> list = new List<student>();
        static Hashtable ht = new Hashtable();
        private static student stu;

        static void Main(string[] args)
        {

            Console.WriteLine("请选择：1.添加学生信息 2.查询学生信息");
            int num = int.Parse(Console.ReadLine());
            switch (num)
            {
                case 1:
                    addinfo();
                    break;

                case 2:
                    inquire();
                    break;

                default:
                    Console.WriteLine("请重新输入！");
                    break;
            }
        }

        private static void inquire()
        {
            throw new NotImplementedException();
        }

        private static void inquire(List<student> stu)
        {
            ht.Add(s1.stuno,s1 );
            ht.Add(s2 .stuno ,s2);
            ht.Add(s3.stuno, s3);
            ht.Add(s4.stuno, s4);
            ht.Add(s5.stuno, s5);
            Console.WriteLine("1，查询所有按学生学号排序");
            Console.WriteLine("2，查询所有按姓名排序");
            Console.WriteLine("3，查询所有按学生年龄排序");
            Console.WriteLine("4，查询");
            Console.WriteLine("5，退出");

            int num1 = int.Parse(Console .ReadLine ());
            switch (num1 )
            {
                case 1:
                    list.Sort(new stuno ());
                    foreach (student  item in stu )
                    {
                        Console.WriteLine(item );
                    }
                    break;
                case 2:
                    list.Sort(new stuname ());
                    foreach (student  item in stu )
                    {
                        Console.WriteLine(item );
                    }
                    break;
                case 3:
                    list.Sort(new age ());
                    foreach (student item in stu)
                    {
                        Console.WriteLine(item);
                    }
                    break;
                case 4:
                    Console.WriteLine("请输入要查找的学生");
                    string no = Console.ReadLine();
                    if (ht.Contains(no ))
                    {
                        Console.WriteLine(ht[no]);
                    }
                    else
                    {
                        Console.WriteLine("没有该学生学号！");
                    }
                    break;
                case 5:
                    Console.WriteLine("恭喜  程序成功 啦！");
                    break;
                default:
                    break;
            }
        }

        private static void addinfo()
        {
            Console.WriteLine("请输入添加学生的学号：");
            string stuno = Console.ReadLine();
            Console.WriteLine("请输入添加学生的姓名：");
            string stuname = Console.ReadLine();
            Console.WriteLine("请输入添加学生的年龄：");
            string age = Console.ReadLine();
            student stu = new student(stuno,stuname ,age);
            if (ht.ContainsKey(stuno))
            {
                Console.WriteLine("该学生的学号已存在！");
            }
            else
            {
                ht.Add(stuno, stuno);
                list.Add(stu);
            }
            Console.WriteLine("请问是否继续");
            string YN = Console.ReadLine();
            if (YN.Equals("n"))
            {
                inquire(list );
            }
            else if (YN.Equals ("y"))
            {
                addinfo();
            }
            else
            {
                Console.WriteLine("请重新输入吧！是或否");
            }
        }


    
        

    }
}

    
    